package com.gaohe.dcp.service.impl;

import java.util.List;

import com.gaohe.common.core.domain.entity.SysRole;
import com.gaohe.common.core.domain.entity.SysUser;
import com.gaohe.common.utils.DateUtils;
import com.gaohe.dcp.domain.vo.DcpSignVo;
import com.gaohe.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.gaohe.dcp.mapper.DcpSignMapper;
import com.gaohe.dcp.domain.DcpSign;
import com.gaohe.dcp.service.IDcpSignService;

/**
 * 用户签名Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-14
 */
@Service
public class DcpSignServiceImpl implements IDcpSignService
{
    @Autowired
    private DcpSignMapper dcpSignMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询用户签名
     *
     * @param signId 用户签名主键
     * @return 用户签名
     */
    @Override
    public DcpSign selectDcpSignBySignId(Long signId)
    {
        return dcpSignMapper.selectDcpSignBySignId(signId);
    }

    /**
     * 查询用户签名列表
     *
     * @param dcpSign 用户签名
     * @return 用户签名
     */
    @Override
    public List<DcpSignVo> selectDcpSignList(DcpSignVo dcpSign)
    {

        List<DcpSignVo> dcpSignVos = dcpSignMapper.selectDcpSignList(dcpSign);
        for (DcpSignVo dcpSignVo : dcpSignVos) {
            if (dcpSignVo.getUserId() != null){
                String nickName = sysUserMapper.selectUserById(dcpSignVo.getUserId()).getNickName();
                dcpSignVo.setNickName(nickName);
            }

        }
        return dcpSignVos;
    }

    /**
     * 新增用户签名
     *
     * @param dcpSign 用户签名
     * @return 结果
     */
    @Override
    public int insertDcpSign(DcpSign dcpSign)
    {
        dcpSign.setCreateTime(DateUtils.getNowDate());
        return dcpSignMapper.insertDcpSign(dcpSign);
    }

    /**
     * 修改用户签名
     *
     * @param dcpSign 用户签名
     * @return 结果
     */
    @Override
    public int updateDcpSign(DcpSign dcpSign)
    {
        dcpSign.setUpdateTime(DateUtils.getNowDate());
        return dcpSignMapper.updateDcpSign(dcpSign);
    }

    /**
     * 批量删除用户签名
     *
     * @param signIds 需要删除的用户签名主键
     * @return 结果
     */
    @Override
    public int deleteDcpSignBySignIds(Long[] signIds)
    {
        return dcpSignMapper.deleteDcpSignBySignIds(signIds);
    }

    /**
     * 删除用户签名信息
     *
     * @param signId 用户签名主键
     * @return 结果
     */
    @Override
    public int deleteDcpSignBySignId(Long signId)
    {
        return dcpSignMapper.deleteDcpSignBySignId(signId);
    }

    @Override
    public List<DcpSignVo> getSignList(Long userId) {
        SysRole role = sysUserMapper.getRole(userId);
        Long roleId = role.getRoleId();
        DcpSignVo dcpSign = new DcpSignVo();
        if (roleId == 100L){
            dcpSign.setUserId(userId);
            List<DcpSignVo> dcpSignVos = this.selectDcpSignList(dcpSign);
            return dcpSignVos;
        }else {
            List<DcpSignVo> dcpSignVos = this.selectDcpSignList(dcpSign);
            return dcpSignVos;
        }
    }
}
